package pt.mynotesmain;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PointF;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;

public class AreaDesenho extends View
implements GestureDetector.OnGestureListener{
		
	GestureDetector gd;
	ArrayList<PointF> Pontos;
	public AreaDesenho(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		gd= new GestureDetector(context,this);
		
	}

	/* (non-Javadoc)
	 * @see android.view.View#onTouchEvent(android.view.MotionEvent)
	 */
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if(gd!=null)
			return gd.onTouchEvent(event);
		// TODO Auto-generated method stub
		return super.onTouchEvent(event);
	}
	
	/* (non-Javadoc)
	 * @see android.view.View#onDraw(android.graphics.Canvas)
	 */
	@SuppressLint("DrawAllocation")
	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		super.onDraw(canvas);
		Paint paint= new Paint(Paint.DITHER_FLAG);
		paint.setColor(Color.argb(255, 128, 0, 0));
		paint.setStrokeWidth(2.0f);
		//paint.setSyle(Paint.Style.Fill);
		paint.setStyle(Paint.Style.FILL);
		canvas.drawLine(10, 20, 30, 0, paint);
		PointF lastponto = null;
		for(PointF point :Pontos){
			if(lastponto!=null)
			canvas.drawLine(lastponto.x, lastponto.y, point.x, point.y, paint);
		}
	}

	public boolean onDown(MotionEvent arg0) {
		// TODO Auto-generated method stub
		Log.v("Log", "cheguei aqui: OnDown");
		Pontos.add(new PointF(arg0.getX(),arg0.getY()));
		invalidate();
		return true;
	}

	public boolean onFling(MotionEvent arg0, MotionEvent arg1, float arg2,
			float arg3) {
		// TODO Auto-generated method stub
		Log.v("Log", "cheguei aqui: OnFling");
		return false;
	}

	public void onLongPress(MotionEvent arg0) {
		// TODO Auto-generated method stub
		Log.v("Log", "cheguei aqui: onLongPress");
		
	}

	public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2,
			float arg3) {
		// TODO Auto-generated method stub
		Log.v("Log", "cheguei aqui: onScroll");
		
		Pontos.add(new PointF(arg1.getX(),arg1.getY()));
		invalidate();
		return false;
	}

	public void onShowPress(MotionEvent arg0) {
		// TODO Auto-generated method stub
		Log.v("Log", "cheguei aqui: onShowPress");
		
	}

	public boolean onSingleTapUp(MotionEvent arg0) {
		// TODO Auto-generated method stub
		Log.v("Log", "cheguei aqui: onSingleTapUp");
		return false;
	}

}
